/**
 * 
 * 组件间的状态共享（类似vue的store）
 * 
 */
import {createContext, useState, useContext} from 'react'

let Context = createContext()

export function useCount() {
  let myCount = useContext(Context)
  return myCount
}

export function ContextProvider3({children}){

  let [state, setState] = useState(0)
  let setObj = {
    state,
    add(v) {
      setState(state+v)
    },
    reduce(v) {
      setState(state-v)
    }
  }

  return (
    <Context.Provider value={setObj}>
      {children}
    </Context.Provider>
  )
}